-- The MIT License (MIT)
-- Copyright (c) 2016 Yanghe Sun

--luacheck: no global
--luacheck: no unused args

local luaunit  = require("luaunit")
local contest  = require("contest")

Test_contest = {}

function Test_contest:testAddDataDir()
    c = contest();
    c:AddDataDir("./testcases/contest/data");
    luaunit.assertEquals(#c._datas, 1);
    luaunit.assertEquals(c._datas[1][1], "test");
end

function Test_contest:testAddSrcDir()
    c = contest();
    c:AddSrcDir("./testcases/contest/src");
    luaunit.assertEquals(#c._member, 4);
end

function Test_contest:testJudge()
    c = contest();
    c:AddDataDir("./testcases/contest/data");
    c:AddSrcDir("./testcases/contest/src");

    function checkall(k, flag)
        for _, v in ipairs(k.detail) do
            luaunit.assertEquals(v.flag, flag);
        end
    end

    checkall(c:Judge(c:GetSrcIndex("cwy"),1), "WRONG_ANSWER");
    checkall(c:Judge(c:GetSrcIndex("qbt"),1), "COMPLETION_ERROR");
    checkall(c:Judge(c:GetSrcIndex("syh"),1), "ACCEPT");
    checkall(c:Judge(c:GetSrcIndex("zzy"),1), "FILE_NOT_FOUND");
end
